const CommonUtil = {
    formatDate : function(Date) {
        var Y = Date.getFullYear();
        var M = Date.getMonth() + 1;
            M = M < 10 ? '0' + M : M;// 不够两位补充0
        var D = Date.getDate();
            D = D < 10 ? '0' + D : D;
        var H = Date.getHours();
            H = H < 10 ? '0' + H : H;
        var Mi = Date.getMinutes();
            Mi = Mi < 10 ? '0' + Mi : Mi;
        var S = Date.getSeconds();
            S = S < 10 ? '0' + S : S;
            return Y + '-' + M + '-' + D + ' ' + H + ':' + Mi + ':' + S;
    },
    formatTimestamp : function(timestamp) {
        return this.formatDate(new Date(timestamp))
    },
    formatSize : function(val) {
        let temp = parseFloat(val) // byte
        if (temp < 1024) return temp.toFixed(2) + "B"
        temp = temp / 1024  //kb
        if (temp < 1024) return temp.toFixed(2) + "KB"
        temp = temp / 1024 //mb
        if (temp < 1024) return temp.toFixed(2) + "MB"
        temp = temp / 1024 //gb
        if (temp < 1024) return temp.toFixed(2) + "GB"
        temp = temp / 1024 //tb
        if (temp < 1024) return temp.toFixed(2) + "TB"
        temp = temp / 1024 //pb
        return temp.toFixed(2) + "PB"
    }
}

export default CommonUtil